﻿using System;
//using System.Collections.Generic;
//using System.ComponentModel;
using System.Data;
//using System.Drawing;
//using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Windows.Forms;
//using System.Runtime.InteropServices;

using System.Data.SqlClient;
using System.IO;
using System.Xml;

namespace FormsAppT8
{
    public partial class Login : Form
    {
       
        public Login()
        {
            InitializeComponent();
            this.DoubleBuffered = true;//设置本窗体
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true); // 禁止擦除背景.
            SetStyle(ControlStyles.DoubleBuffer, true); // 双缓冲
        }
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0014) //禁掉清除背景消息
                return;
            base.WndProc(ref m);
        }

        //private Order_start O_st;
        //private Order_end O_end;
        //private Process_Order P_Order;
        private void Login_Load(object sender, EventArgs e)
        {
            //loginTxtWR  lg = new loginTxtWR();
            //Common.SqlString = sql.ConfigGetValue();
            //this.button1.CanFocus();
            //this.textBox2.Focus();
            UserSQLClass sql = new UserSQLClass();
            //Common.SqlString = sql.ConfigGetValue();
            string passTag,user,pass,ty;
            string fileName = Application.StartupPath + "\\login.xml";

            //读文件内容，加载历史数据；没有时初始配置文件
            if (!File.Exists(fileName))
            {
                sql.initLogin();
            }

            passTag = loginTxtWR.GetV("//users", "passTag");
            user = loginTxtWR.GetV("//users", "user");
            pass = loginTxtWR.GetV("//users", "pass");
            checkBox1.Checked = bool.Parse(passTag);
            textBox1.Text = user;
            if (checkBox1.Checked)
            {
               // textBox2.Text =sql.Getpass(pass);
            }
            ty= loginTxtWR.GetV("//users", "company");
        }


        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DataLink fff = new DataLink();
            fff.ShowDialog();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            //try
            //{
            //    UserSQLClass usql = new UserSQLClass();
            //    //, uuid, regNo, str
            //    string passTag, user, pass;
            //    bool passTagBool = this.checkBox1.Checked;
            //    passTag = passTagBool.ToString();
            //    user = this.textBox1.Text.Trim();
            //    pass = this.textBox2.Text.Trim();                               

            //    #region *********************用户验证

            //    //Common.SqlString = usql.ConfigGetValue111();
            //    //SqlConnection Mycon = new SqlConnection(usql.ConfigGetValue111());//Common.SqlString);

            //    ////用户验证
            //    //StringBuilder MySQL1 = new StringBuilder("SELECT Username,CU_PDAPWD FROM capMembership where UserId='" + user + "'");
            //    //Mycon.Open();//??
            //    //SqlDataAdapter Mydata1 = new SqlDataAdapter(MySQL1.ToString(), Mycon);
            //    //DataSet Mytable1 = new DataSet();
            //    //Mydata1.Fill(Mytable1, "person");
            //    //if (Mytable1.Tables["person"].Rows.Count == 0)
            //    //{
            //    //    MessageBox.Show("当前系统中没有使用的用户名！\n\n请检查！",
            //    //                     "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    //}
            //    //else 
            //    if (pass =="123456")
            //    {
            //        XmlDocument xDoc = new XmlDocument();
            //        //设置本次登录用户与登录时间到App.config文件中                       

            //        xDoc.Load("login.xml");
            //        XmlElement xElem1 = (XmlElement)xDoc.SelectSingleNode("//users");
            //        xElem1.SetAttribute("user", user);
            //        xElem1.SetAttribute("name", "admin");
            //        xElem1.SetAttribute("passTag", passTag);
            //        if (passTagBool)
            //        { xElem1.SetAttribute("pass", "123456"); }
            //        else
            //        { xElem1.SetAttribute("pass","123456"); }

            //        if (-1 == DateTime.Now.CompareTo(Convert.ToDateTime(xElem1.GetAttribute("time"))))
            //        {
            //            MessageBox.Show("当前时间晚于上次登录时间！\n\n系统时间异常，请检查！", "信息提示",
            //                               MessageBoxButtons.OK, MessageBoxIcon.Information);
            //        }
            //        xElem1.SetAttribute("time", System.DateTime.Now.ToString());
            //        xDoc.Save("login.xml");

            //        //this.WindowState = FormWindowState.Minimized;

            //        ////处理保存数据库，解决多点登录的现象
            //        //Random ran = new Random();
            //        //Common.UUIDInt = ran.Next(10000000, 1000000000);
            //        //Common.userStr = user;
            //        //String timeStr = loginTxtWR.GetNowTimeStr();          //时间是比实际时间晚8小时的

            //        //MySQL1 = new StringBuilder("UPDATE capMembership SET CU_LoginTime=" + timeStr +
            //        //                                                   ",CU_LoginUUID='" + Common.UUIDInt +
            //        //                                                   "',CU_LoginState='online' WHERE UserId='" + user + "'");
            //        //SqlCommand Mycom = new SqlCommand(MySQL1.ToString(), Mycon);
            //        //Mycom.ExecuteNonQuery();

            //        //Mycon.Close();
            //        //Mydata1.Dispose();

            //        this.DialogResult = DialogResult.OK;
            //        //this.Close();

            //        //this.Close();                                     //中途正常退出
            //    }
            //    else
            //    {
            //       // Mycon.Close();
            //        //Mydata1.Dispose();
            //        MessageBox.Show("密码输入错误！\n\n密码区分大小字母，请重新输入正确的密码！", "信息提示",
            //                   MessageBoxButtons.OK, MessageBoxIcon.Information);

            //    }

            //    #endregion

            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message, "信息提示",MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    Application.Exit();
            //}

        }
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            //if (System.Diagnostics.Process.GetProcessesByName("TabTip").Length < 1)
            //{
            //    System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe");
            //}
            //if (System.Diagnostics.Process.GetProcessesByName("TabTip").Length < 1)
            //{
            //    System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe");
            //}
        }
        private void textBox2_Click(object sender, EventArgs e)
        {
           // System.Diagnostics.Process.Start(@"C:\Program Files\Common Files\microsoft shared\ink\TabTip.exe");
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
